package com.jlz.beans.def;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.jlz.managers.def.Divisions;
import com.julewa.db.DB;
import com.julewa.db.Entity;

/*
 * 地理位置划分表
 * 主要是行政区域划分
 * 这将很重要
 * 
 */

@DB.USECACHE

@Component @Scope(Entity.SCOPE)
public class DivisionBean  extends Entity<Long>{
	
	@DB.COLUMN Long parentId;
	@DB.COLUMN int type;
	@DB.COLUMN int level;
	@DB.COLUMN String label;
	@DB.COLUMN int postcode;//如为0
	@DB.COLUMN long x;
	@DB.COLUMN long y;
	@DB.COLUMN int round;
	
	//
	private @Autowired Divisions divisions;
	//
	@DB.DEPENDON("label") String fullLabel = null;
	@DB.DEPENDON("parentId") DivisionBean parentDivision = null;
	//
	@DB.DEPENDON("parentId") List<DivisionBean> parentDivisions = null;
	List<DivisionBean> childrenDivisions = null;
	//

	public int getLevel() {
		return level;
	}
	public Long getParentId() {
		return parentId;
	}
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	public List<DivisionBean> getParentDivisions() {
		if(parentDivisions == null){
			parentDivisions = divisions.getParentsOf(this);
		}
		return parentDivisions;
	}
	public void setParentDivisions(List<DivisionBean> parentDivisions) {
		this.parentDivisions = parentDivisions;
	}
	public List<DivisionBean> getChildrenDivisions() {
		if(childrenDivisions==null){
			childrenDivisions = divisions.getChildrenOf(this);
		}
		return childrenDivisions;
	}
	public void setChildrenDivisions(List<DivisionBean> childrenDivisions) {
		this.childrenDivisions = childrenDivisions;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public int getPostcode() {
		return postcode;
	}
	public void setPostcode(int postcode) {
		this.postcode = postcode;
	}
	public long getX() {
		return x;
	}
	public void setX(long x) {
		this.x = x;
	}
	public long getY() {
		return y;
	}
	public void setY(long y) {
		this.y = y;
	}
	public int getRound() {
		return round;
	}
	public void setRound(int round) {
		this.round = round;
	}
	public String getFullLabel() {
		if(fullLabel == null){
			DivisionBean p = this.getParentDivision();
			if(p == null){
				fullLabel = label;
			}else{
				fullLabel = p.getFullLabel() + " " + label;
			}
		}
		return fullLabel;
	}
	public void setFullLabel(String fullLabel) {
		this.fullLabel = fullLabel;
	}
	public DivisionBean getParentDivision() {
		if(this.parentDivision == null){
			if(parentId == null || parentId.equals(getID()))return null;
			this.parentDivision = divisions.getDivision(parentId);
		}
		return parentDivision;
	}
	public void setParentDivision(DivisionBean parentDivision) {
		this.parentDivision = parentDivision;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}

}
